import {DialogButton} from "../../solar/w3ts/handles/dialog";

export default class GameDifficultyChooseDialogState {

    static config: {
        hasEndlessMode: boolean,
        AddPlayerTechId?: string
    } = {
        hasEndlessMode: false,
        AddPlayerTechId:"qbk1"
    }


    constructor() {
        let triggerHandle = CreateTrigger();
        TriggerRegisterTimerEventSingle(triggerHandle, 0.50);
        TriggerAddAction(triggerHandle, GameDifficultyChooseDialogState.action);

    }

    static action(this: void) {

        let dialog = DialogCreate();
        DialogSetMessage(dialog, "难度选择");
        for (let i = 1; i <= 9; i++) {
            let button = DialogAddButton(dialog, "难度" + i + "", 0);
            DialogButton.fromHandle(button).solarData.GameDifficulty = i
            DialogButton.fromHandle(button).solarData.isEndlessMode = false
        }
        if (GameDifficultyChooseDialogState.config.hasEndlessMode) {
            let button = DialogAddButton(dialog, "无尽模式", 0);
            DialogButton.fromHandle(button).solarData.GameDifficulty = 4
            DialogButton.fromHandle(button).solarData.isEndlessMode = true
        }
        DialogDisplay(Player(0), dialog, true);
        // onclick Trigger
        let ydl_trigger = CreateTrigger();
        TriggerRegisterDialogEvent(ydl_trigger, dialog);
        TriggerAddAction(ydl_trigger, GameDifficultyChooseDialogState.on_dialog_click);

    }


    ///

    static on_dialog_click(this: void): void {
        let button = GetClickedButton();
        let gameDifficultyTemp = DialogButton.fromHandle(button).solarData.GameDifficulty
        let isEndlessModeTemp: boolean = DialogButton.fromHandle(button).solarData.isEndlessMode
        if (gameDifficultyTemp) {
            gameDifficulty = gameDifficultyTemp;
        }
        if (isEndlessModeTemp) {
            isEndlessMode = isEndlessModeTemp;
        }
        DisplayTimedTextToForce(GetPlayersAll(), 15.00, "|CFFFF0000选择的难度 ： 难度" + gameDifficulty);

        if (GameDifficultyChooseDialogState.config.AddPlayerTechId && GameDifficultyChooseDialogState.config.AddPlayerTechId.length > 3) {
            let techLv = gameDifficulty - 1
            techLv = techLv * techLv
            AddPlayerTechResearched(Player(11), FourCC(GameDifficultyChooseDialogState.config.AddPlayerTechId), techLv);
            AddPlayerTechResearched(Player(12), FourCC(GameDifficultyChooseDialogState.config.AddPlayerTechId), techLv);
        }
    }


}

